<h2>创建任务</h2>
<div id="otherInfo">
	<div class="fitem">
		<label>任务标题:</label>
		<input id="title" style="width:145px;" required="true">
	</div>
	<div class="fitem">
		<label>执行者:</label>
		<input id="assignee" name="assignee" style="width:150px" class="easyui-validatebox" required="true">
	</div>
	<div class="fitem">
		<label>任务相关项:</label>
		<select  name="relate" id="relate" style="display: none;" class="easyui-combobox combobox-f combo-f">
			<option value="opportunity">商业机会</option>
			<option value="consult">咨询</option>
		</select>
		<input name="relateId" id="relateId" type="hidden">
		<input name="relateName" id="relateName" style="width:150px">
	</div>
	<div class="fitem">
		<label>任务结束时间:</label>
		<input name="endDate" id="endDate" type="text" class="easyui-datetimebox" required="required" style="width:150px">
	</div>
	<div class="fitem">
		<label>优先级:</label>
		<select class="easyui-combobox" name="priority" id="priority">
			<option value="normal">普通</option>
			<option value="high">高</option>
		</select>
	</div>
	<div class="fitem">
		<label>描述:</label>
		<textarea  id="description" name="description" style="width:200px;height:80px"></textarea>
	</div>
	
	<a href="javascript:void(0)" class="easyui-linkbutton" onclick="javascript:createTaskJs.add()">添加</a>
</div>

<script type="text/javascript">
(function(createTaskJs, $, undefined ) {
	
	var url = "dispatch/utility/task/add"
	createTaskJs.init = function(){
		workbenchJs.loadData("dispatch/manage/employee/simpleAll",createTaskJs.loadEmployeeResult,"查询用户列表");
		if(taskActionJs.getRelate() != null && taskActionJs.getRelate() != '')
		{
			//alert(taskActionJs.getRelate());
			//$('#relate').combobox('setValue','consult');
			
			$('#relate').val(taskActionJs.getRelate());
			$('#relate').attr("disabled",true);
			$('#relateId').val(taskActionJs.getRelateId());
			$('#relateName').combobox({
				url:null,
				valueField:'name',
				textField:'name',
				multiple:false,
				panelHeight:'auto',
				editable:false,
				data:[{
					'name' : taskActionJs.getRelateName()
				}]
			});
			$('#relateName').combobox('setValue',taskActionJs.getRelateName());
			url = taskActionJs.getUrl();
			//$('#relateName').attr("disabled",true);
		}
	};
	
	createTaskJs.loadEmployeeResult = function(result){
		var payload = jQuery.parseJSON(result.payload.value);
		$('#assignee').combobox({
			url:null,
			valueField:'name',
			textField:'name',
			multiple:false,
			panelHeight:'auto',
			data:payload
		});
	};
	createTaskJs.add = function(){
    	var json = {};
    	json.title = $("#title").val();
    	json.assignee = $("input[name='assignee']").val();
    	json.description = $("#description").val();
    	json.endDate = $("input[name='endDate']").val();
    	json.priority = $('#priority').val();
    	json.relate = $('#relate').val();
    	json.relateID = parseInt($('#relateId').val());
		json.relateName = $('#relateName').combobox('getValue');
    	var str = $.toJSON(json);
    	str = 'parameters='+str;
    	
		$.ajax({
            type: "post",
            url: url,
            dataType:"json",
            data: str,
            cache: false,
            success: function (result) {
            	var res = result.result;
                if(res == "SUCCESS")
                {
                	
                	var message = "添加成功";
                	$.messager.alert('Success',message,'info',function(){
                		
                    		if(taskActionJs.getCallBack() != null)
                    		{
                    			var callback = taskActionJs.getCallBack();
                    			callback(result);
                    		}
                        });	
                	
                }else if(res == "COMPONENT_ERROR")
                {
                	$.messager.alert("Error",result.payload.value);
                }else
                {
                	$.messager.alert("Error",result.result);
                }
                
            }
            
        });
	}
}( window.createTaskJs = window.createTaskJs || {}, jQuery ));

    $(function(){
    	createTaskJs.init();
    });
</script>
 <style type="text/css">
        .ftitle{
            font-size:14px;
            font-weight:bold;
            padding:5px 0;
            margin-bottom:10px;
            border-bottom:1px solid #ccc;
        }
        .fitem{
            margin-bottom:5px;
        }
        .fitem label{
            display:inline-block;
            width:80px;
        }
        #comment{
        	padding:3px;
        }
 </style>